package com.ygqh.baby.controller.admin;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.foxinmy.weixin4j.util.StringUtil;
import com.mumu.commons.excel.ExcelHandler;
import com.mumu.commons.excel.ExcelWriteDataTemplate;
import com.mumu.commons.excel.exception.ExcelException;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.handler.BiOrderStatisticsHandler;
import com.ygqh.baby.handler.OrderCountHandler;
import com.ygqh.baby.model.*;
import com.ygqh.baby.model.wdt.qyb.WdtShop;
import com.ygqh.baby.po.*;
import com.ygqh.baby.service.*;
import com.ygqh.baby.service.task.YgBiTaskService;
import com.ygqh.baby.service.wdtqyb.api.WdtQybApi;
import com.ygqh.baby.utils.DateConvertUtils;
import com.ygqh.baby.utils.DocumentHandler;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/admin/report")
public class ReportController extends BaseController<Object, java.lang.Long> {

    @Autowired
    private BiOrderDayService biOrderDayService;
    @Autowired
    private YgProductService ygProductService;
    @Autowired
    private YgAddedUsersService ygAddedUsersService;
    @Autowired
    private BiChannelDayService biChannelDayService;
    @Autowired
    private YgBiTaskService biTaskService;
    @Autowired
    private YgSkuService ygSkuService;
    @Autowired
    private BiSkuSaleService biSkuSaleService;
    @Autowired
    private FileService fileService;
    @Autowired
    private BiSupplierOrderDayService biSupplierOrderDayService;
    @Autowired
    private YgDrawPrizeRecordService ygDrawPrizeRecordService;
    @Autowired
    private WdtQybApi wdtQybApi;
    @Autowired
    private YgPlatformService ygPlatformService;
    @Autowired
    private BiOrderStatisticsHandler biOrderStatisticsHandler;
    @Autowired
    private OrderCountHandler orderCountHandler;

    @RequestMapping("searchOrderReport")
    @ResponseBody
    public Map<String, Object> searchOrderReport(String shopName, String shopNo, @RequestParam(defaultValue = "0") String warehouseNo, QueryInfo queryInfo,
                                                 @RequestParam Date startDate, @RequestParam Date endDate) {
        if ("002".equals(shopNo)) {
            shopNo = "M000";
        }
        ResultSet<BiOrderDay> result = biOrderDayService.search(queryInfo, startDate, endDate, shopNo, shopName, warehouseNo);
        BigDecimal totalPayPrice = BigDecimal.ZERO;
        if (result.getTotal() > 0) {
            totalPayPrice = biOrderDayService.getTotalPayPriceByShop(startDate, endDate, shopNo, shopName, warehouseNo);
        }
        return result.toDatatables(totalPayPrice.toString());
    }

    @RequestMapping("resetBiOrderDay")
    @ResponseBody
    public Message resetBiOrderDay(String shopNo, @RequestParam Date startDate, @RequestParam Date endDate) {
        if ("002".equals(shopNo)) {
            shopNo = "M000";
        }
        return biOrderStatisticsHandler.resetBiOrderDay(shopNo, startDate, endDate);
    }

    @RequestMapping("delCache")
    @ResponseBody
    public Message delCache() {
        Set<String> strings = biOrderStatisticsHandler.delCache();
        return Message.success(strings);
    }

    @RequestMapping("searchOrderReportByTime")
    @ResponseBody
    public Map<String, Object> searchOrderReportByTime(/*String q, QueryInfo queryInfo, */
            Date startDate, Date endDate) {
        List<BiOrderDay> dayList = biOrderDayService.executeOrderStatisticsNew(startDate, endDate, "M000");
        ResultSet<BiOrderDay> resultSet = new ResultSet<>(1L, dayList);
        return resultSet.toDatatables(null);
    }

    @RequestMapping("searchOrderReportBySupplier")
    @ResponseBody
    public Map<String, Object> searchOrderReportBySupplier(Date startDate, Date endDate) {
        List<BiSupplierOrderDay> list = biSupplierOrderDayService.
                statisticsSupplierOrderByDay(startDate, endDate, true, false);
        ResultSet<BiSupplierOrderDay> resultSet = new ResultSet<>(1L, list);
        return resultSet.toDatatables(null);
    }

    @RequestMapping("searchSourceReport")
    @ResponseBody
    public Map<String, Object> searchSourceReport(String q, QueryInfo queryInfo, Date startDate, Date endDate) {
        ResultSet<BiChannelDay> result = biChannelDayService.search(queryInfo, startDate, endDate, q);
        return result.toDatatables(null);
    }

    @RequestMapping("searchProductReport")
    @ResponseBody
    public Map<String, Object> searchProductReport(HotProductSaleQueryReq queryReq) {
        ResultSet<YgHotProductModel> result = ygProductService.searchHotProduct(queryReq);
        return result.toDatatables(null);
    }

    @RequestMapping("searchProductReportBate")
    @ResponseBody
    public Map<String, Object> searchProductReportBate(QueryInfo queryInfo, Date startDate, Date endDate, String shopNo,
                                                       String shopName, String productCode, String productName, Date salesStartDate, Date salesEndDate) {
        ResultSet<BiSkuSale> result = biSkuSaleService.searchBiProductSaleList(queryInfo, startDate, endDate, shopNo,
                shopName, productCode, productName, salesStartDate, salesEndDate);
        return result.toDatatables(null);
    }

    @RequestMapping("getProductSalesByShop")
    @ResponseBody
    public List<BiSkuSale> getProductSalesByShop(Date startDate, Date endDate, String shopNo, String productCode) {
        return biSkuSaleService.searchBiProductByShop(startDate, endDate, shopNo, productCode);
    }

    @RequestMapping("getProductSalesBySku")
    @ResponseBody
    public List<BiSkuSale> getProductSalesBySku(Date startDate, Date endDate, String shopNo, String productCode) {
        return biSkuSaleService.searchBiProductBySku(startDate, endDate, shopNo, productCode);
    }

    @RequestMapping("exportProductReport")
    public void exportProductReport(Date startDate, Date endDate, String shopNo, String shopName, String productCode,
                                    String productName, Date salesStartDate, Date salesEndDate, HttpServletRequest request,
                                    HttpServletResponse response) {
        QueryInfo q = new QueryInfo();
        q.setEnd(20000);
        if ("-1".equals(shopNo)) {
            shopNo = "";
        }

        endDate = DateConvertUtils.addDay(endDate, 1);
        ResultSet<BiSkuSale> result = biSkuSaleService.searchBiProductSaleList(q, startDate, endDate, shopNo, shopName,
                productCode, productName, salesStartDate, salesEndDate);
        List<BiSkuSale> resultList = result.getResult();
        List<BiSkuSale> skuList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(resultList)) {
            List<String> productCodes = resultList.stream().map(BiSkuSale::getProductCode).collect(Collectors.toList());
            skuList = biSkuSaleService.searchBiProductBySku(startDate, endDate, shopNo,
                    productCodes.toArray(new String[]{}));
        }
        byte[] bytes = fileService.downloadFromOss("template/productreport.xls");
        Map<String, Object> dataMap = new HashMap<>(2);
        dataMap.put("resultSet", resultList);
        dataMap.put("skuList", skuList);
        DocumentHandler.DownloadExcel(bytes, "销售统计.xls", dataMap, request, response);
    }

    @RequestMapping("getSkuReport")
    @ResponseBody
    public List<YgSkuReport> getSkuReport(String productCode, Date startDate, Date endDate) {
        return ygSkuService.getSkuReport(productCode, startDate, endDate);
    }

    @RequestMapping("searchUserReport")
    @ResponseBody
    public Map<String, Object> searchUserReport(String q, QueryInfo queryInfo, Date startDate, Date endDate) {
        ResultSet<YgAddedUsers> result = ygAddedUsersService.search(queryInfo, q, startDate, endDate);
        return result.toDatatables(null);
    }

    /**
     * 修复数据
     *
     * @param startDate
     * @param callback
     * @return
     */
    @RequestMapping("repairData")
    @ResponseBody
    public JSONPObject repairData(Date startDate, String callback) {
        JSONPObject json;
        Date currentTime = new Date();
        long diffDate = DateConvertUtils.diffDayes(startDate, currentTime);
        for (int i = 0; i < diffDate; i++) {
            BiOrderDay profit = biTaskService.executeOrderDateGrossProfit(DateConvertUtils.addDay(startDate, i),
                    DateConvertUtils.addDay(startDate, i + 1));
            if (profit == null) {
                profit = new BiOrderDay();
                profit.setTotalCostPrice(new BigDecimal(0));
                profit.setGrossMargin(new BigDecimal(0));
            }
            profit.setOrderDate(DateConvertUtils.formatToDate(DateConvertUtils.addDay(startDate, i),
                    DateConvertUtils.DATE_FORMAT));
            biOrderDayService.updateByDate(profit);
        }
        json = new JSONPObject(callback, Message.success("", diffDate));
        return json;
    }

    @RequestMapping("drawReport")
    @ResponseBody
    public Map<String, Object> drawReport(String sourceCode) {
        ResultSet<DrawReport> result = ygDrawPrizeRecordService.drawReport(sourceCode);
        return result.toDatatables(null);
    }

    @RequestMapping("drawReportTotal")
    @ResponseBody
    public Map<String, Object> drawReportTotal(String sourceCode) {
        return ygDrawPrizeRecordService.selectDrawSizeTotal(sourceCode);
    }

    @RequestMapping("searchSupplierOrderReport")
    @ResponseBody
    public Map<String, Object> searchSupplierOrderReport(QueryInfo queryInfo, String q, Date startDate, Date endDate, Long supplierId) {
        ResultSet<BiSupplierOrderDay> resultSet = biSupplierOrderDayService.search(queryInfo, q, startDate, endDate, supplierId);
        return resultSet.toDatatables(null);
    }

    @RequestMapping("searchSupplierOrderReportByMonth")
    @ResponseBody
    public Map<String, Object> searchSupplierOrderReportByMonth(QueryInfo queryInfo, Date startDate, Date endDate) {
        ResultSet<BiSupplierOrderDay> resultSet = biSupplierOrderDayService.searchaByMonth(queryInfo, startDate, endDate);
        return resultSet.toDatatables(null);
    }

    /**
     * 指定日期，区分壹果品牌和其它品牌订单数据
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("supplierOrderReportWithSplitYG")
    @ResponseBody
    public Message supplierOrderReportWithSplitYG(@RequestParam Date startDate, @RequestParam Date endDate) {
        return Message.success(biSupplierOrderDayService.supplierOrderReportWithSplitYG(startDate, endDate));
    }

    /**
     * 指定月份，区分壹果品牌和其它品牌订单数据
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("supplierOrderReportWithSplitYGByMonth")
    @ResponseBody
    public Message supplierOrderReportWithSplitYGByMonth(Date startDate, Date endDate) {
        startDate = DateConvertUtils.getDateStart(startDate);
        endDate = DateConvertUtils.getDateStart(endDate);
        return Message.success(biSupplierOrderDayService.supplierOrderReportWithSplitYG(startDate, endDate));
    }

    /**
     * 指定日期，按品牌统计每日订单数据(过滤壹果)
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("supplierOrderReportByDay")
    @ResponseBody
    public Message supplierOrderReportByDay(Date startDate, Date endDate) {
        return biSupplierOrderDayService.supplierOrderReportByDay(startDate, endDate);
    }

    /**
     * 指定月份，按品牌统计订单数据(过滤壹果)
     *
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @return
     */
    @RequestMapping("supplierOrderReportByMonth")
    @ResponseBody
    public Message supplierOrderReportByMonth(Date startDate, Date endDate) {
        return biSupplierOrderDayService.supplierOrderReportByMonth(startDate, endDate);
    }

    /**
     * 重置指定时间内的品牌统计数据
     *
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @return
     */
    @RequestMapping("resetSupplierReport")
    @ResponseBody
    public Message resetSupplierReport(@RequestParam Date startDate, @RequestParam Date endDate) {
        startDate = DateConvertUtils.getDateStart(startDate);
        endDate = DateConvertUtils.addDay(DateConvertUtils.getDateStart(endDate), 1);
        return biSupplierOrderDayService.resetSupplierReport(startDate, endDate);
    }

    /**
     * 导出指定时间内的品牌统计数据
     *
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @param request   request
     * @param response  response
     */
    @RequestMapping("exportSupplierReport")
    public void exportSupplierReport(@RequestParam Date startDate, @RequestParam Date endDate, HttpServletRequest request, HttpServletResponse response) {
        startDate = DateConvertUtils.getDateStart(startDate);
        endDate = DateConvertUtils.addDay(DateConvertUtils.getDateStart(endDate), 1);
        List<BiSupplierOrderDay> resultList = biSupplierOrderDayService.findList(null, null, startDate, endDate, null);
        byte[] bytes = fileService.downloadFromOss("template/bi_supplier_day_report.xlsx");
        Map<String, Object> dataMap = new HashMap<>(1);
        dataMap.put("resultSet", resultList);
        dataMap.put("exportDate", DateConvertUtils.format(startDate) + "~"
                + DateConvertUtils.format(DateConvertUtils.addDay(DateConvertUtils.getDateStart(endDate), -1)));
        DocumentHandler.DownloadExcel(bytes, "品牌销售统计.xls", dataMap, request, response);
    }

    /**
     * 销售月报
     *
     * @param queryInfo     分页参数
     * @param startMonth    开始月份
     * @param endMonth      结束月份
     * @param platformNo    销售平台
     * @param groupSupplier 是否根据商家分组
     * @param splitYg       是否区分壹果和第三方
     * @return
     */
    @RequestMapping("supplierOrderReportByMonthAndPlatform")
    @ResponseBody
    public Map<String, Object> supplierOrderReportByMonthAndPlatform(QueryInfo queryInfo, Date startMonth,
                                                                     Date endMonth, String platformNo,
                                                                     boolean groupSupplier, boolean splitYg) {
        ResultSet<BiSupplierOrderDay> resultSet = biSupplierOrderDayService
                .searchSupplierOrderReportByMonth(queryInfo, startMonth, endMonth, platformNo, groupSupplier, splitYg);
        return resultSet.toDatatables(null);
    }

    /**
     * 销售看板
     *
     * @return
     */
    @RequestMapping("getSalesBoardData")
    @ResponseBody
    public Map<String, Object> getSalesBoardData() {
        Date date = DateConvertUtils.getDateStart(new Date());
        //旺店通增量数据
        QueryInfo queryInfo = new QueryInfo();
        queryInfo.setStart(0);
        queryInfo.setEnd(10);
        BigDecimal totalOrderPrice = biOrderDayService.getTotalOrderPrice(date, date);
        List<BiOrderDay> list = biOrderDayService.findList(queryInfo, date, date);
        list.sort((o1, o2) -> -o1.getTotalOrderPrice().compareTo(o2.getTotalOrderPrice()));
        Map<String, Object> map = new HashMap<>();
        map.put("totalOrderPrice", totalOrderPrice);
        map.put("dataList", list);
        return map;
    }

    @RequestMapping("searchHotProductReport")
    @ResponseBody
    public Map<String, Object> searchHotProductReport(HotProductSaleQueryReq queryReq, String shopName) {
        ResultSet<YgHotProductModel> result;
//        List<Map<String, String>> platformList = ygWholesalerService.findPlatformList();
//        System.out.println(platformList);
//        long count = platformList.stream().filter(map -> map.get("platformNo").equals(shopNo)).count();
        if (StringUtil.isBlank(queryReq.getShopNo()) || "M000".equals(queryReq.getShopNo())
                || "M001".equals(queryReq.getShopNo()) || "M003".equals(queryReq.getShopNo())) {
            result = ygProductService.searchHotProduct(queryReq);
        } else {
            result = biSkuSaleService.searchHotProduct(queryReq, queryReq.getStartDate(), queryReq.getEndDate(), queryReq.getShopNo(),
                    shopName, queryReq.getProductName());
        }
        return result.toDatatables(null);
    }

    @RequestMapping("getAllWdtShop")
    @ResponseBody
    public Message getAllWdtShop() {
        List<WdtShop> allShop = wdtQybApi.getAllShop();
        List<YgPlatform> ygPlatforms = ygPlatformService.find();
        for (YgPlatform ygPlatform : ygPlatforms) {
            if (!ygPlatform.getPlatformNo().equals("M000")) {
                WdtShop wdtShop = new WdtShop();
                wdtShop.setShopNo(ygPlatform.getPlatformNo());
                wdtShop.setShopName(ygPlatform.getName());
                allShop.add(wdtShop);
            }
        }
//        String json =  "[{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":44,\"shop_name\":\"Yiigoo官方旗舰店（卓逸荟）\",\"shop_no\":\"0070\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":44,\"shop_name\":\"壹家店\",\"shop_no\":\"M001\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":44,\"shop_name\":\"新世界\",\"shop_no\":\"M002\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":44,\"shop_name\":\"太阳宫\",\"shop_no\":\"TaiYangGong\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":0,\"province\":\"0\",\"shop_id\":46,\"shop_name\":\"Yiigoo官方旗舰店（少爷家的店）\",\"shop_no\":\"0071\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":47,\"shop_name\":\"Yiigoo官方旗舰店（暖暖妈爱分享）\",\"shop_no\":\"0073\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":48,\"shop_name\":\"Yiigoo官方旗舰店（美好Plus）\",\"shop_no\":\"075\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":49,\"shop_name\":\"平安银行信用卡\",\"shop_no\":\"076\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":50,\"shop_name\":\"Yiigoo官方旗舰店（冰火火）\",\"shop_no\":\"078\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":51,\"shop_name\":\"Yiigoo官方旗舰店（金华奇趣）\",\"shop_no\":\"079\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":52,\"shop_name\":\"Yiigoo官方旗舰店（萌芽研究所）\",\"shop_no\":\"080\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":53,\"shop_name\":\"Yiigoo官方旗舰店（万物心选）\",\"shop_no\":\"081\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":54,\"shop_name\":\"Yiigoo官方旗舰店（三个妈妈六个娃）\",\"shop_no\":\"082\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":55,\"shop_name\":\"Yiigoo官方旗舰店（小仙团购）\",\"shop_no\":\"099\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":56,\"shop_name\":\"Yiigoo官方旗舰店（朵妈）\",\"shop_no\":\"098\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":57,\"shop_name\":\"Yiigoo官方旗舰店（i陪娃）\",\"shop_no\":\"097\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":59,\"shop_name\":\"Yiigoo官方旗舰店（多么生活）\",\"shop_no\":\"095\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":61,\"shop_name\":\"Yiigoo官方旗舰店（达妈）\",\"shop_no\":\"093\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":63,\"shop_name\":\"Yiigoo官方旗舰店（常青藤爸爸）\",\"shop_no\":\"083\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":70,\"province\":\"0\",\"shop_id\":65,\"shop_name\":\"Yiigoo官方旗舰店（每日一淘）\",\"shop_no\":\"092\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":67,\"shop_name\":\"Yiigoo官方旗舰店（NEWMALL）\",\"shop_no\":\"091\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"1343416141\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":72,\"province\":\"0\",\"shop_id\":70,\"shop_name\":\"Yiigoo官方旗舰店（小米有鱼）\",\"shop_no\":\"089\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":68,\"province\":\"0\",\"shop_id\":71,\"shop_name\":\"Yiigoo官方旗舰店（爱库存）\",\"shop_no\":\"050\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":66,\"province\":\"0\",\"shop_id\":72,\"shop_name\":\"Yiigoo官方旗舰店（好衣库）\",\"shop_no\":\"051\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"2291941387\",\"account_nick\":\"seanchenjl\",\"address\":\"\",\"city\":\"0\",\"contact\":\"壹果\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":1,\"province\":\"0\",\"shop_id\":1,\"shop_name\":\"Yiigoo官方旗舰店（淘宝）\",\"shop_no\":\"001\",\"sub_platform_id\":0,\"telno\":\"010-57238965\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":2,\"shop_name\":\"Yiigoo壹果\",\"shop_no\":\"002\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"9572795440\",\"account_nick\":\"Yiigoo官方旗舰店\",\"address\":\"\",\"city\":\"0\",\"contact\":\"壹果\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":3,\"province\":\"0\",\"shop_id\":4,\"shop_name\":\"Yiigoo官方旗舰店（京东）\",\"shop_no\":\"004\",\"sub_platform_id\":0,\"telno\":\"010-57238965\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":6,\"shop_name\":\"Yiigoo VIP\",\"shop_no\":\"006\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"南京市江宁区江宁经济技术开发区苏源大道87号YOHO！有货物流中心东一楼\",\"city\":\"320100\",\"contact\":\"苏道金\",\"district\":\"320115\",\"mobile\":\"15366054151\",\"platform_id\":127,\"province\":\"320000\",\"shop_id\":7,\"shop_name\":\"Yiigoo官方旗舰店（有货）\",\"shop_no\":\"007\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":8,\"shop_name\":\"Yiigoo官方旗舰店（爸妈营）\",\"shop_no\":\"008\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"33C2E34804507CD5F2A89B95A0DA0CC8\",\"account_nick\":\"20778\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":14,\"province\":\"0\",\"shop_id\":9,\"shop_name\":\"Yiigoo官方旗舰店（唯品会）\",\"shop_no\":\"009\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":10,\"shop_name\":\"Yiigoo官方旗舰店（科学家庭育儿商城）\",\"shop_no\":\"010\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":11,\"shop_name\":\"Yiigoo官方旗舰店（Patpat）\",\"shop_no\":\"011\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":13,\"shop_name\":\"Yiigoo官方旗舰店（Seties）\",\"shop_no\":\"013\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":14,\"shop_name\":\"Yiigoo使用\",\"shop_no\":\"014\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":15,\"shop_name\":\"Yiigoo官方旗舰店（够赞）\",\"shop_no\":\"015\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":17,\"shop_name\":\"Yiigoo官方旗舰店（华为生活）\",\"shop_no\":\"017\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"3339882339\",\"account_nick\":\"yiigoo91\",\"address\":\"\",\"city\":\"0\",\"contact\":\"壹果\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":1,\"province\":\"0\",\"shop_id\":22,\"shop_name\":\"拾光研所旗舰店（淘宝）\",\"shop_no\":\"022\",\"sub_platform_id\":0,\"telno\":\"010-57238965\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":23,\"shop_name\":\"Yiigoo官方旗舰店（大V店）\",\"shop_no\":\"023\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"3356304411\",\"account_nick\":\"yiigoo壹果旗舰店\",\"address\":\"\",\"city\":\"0\",\"contact\":\"壹果\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":1,\"province\":\"0\",\"shop_id\":24,\"shop_name\":\"Yiigoo官方旗舰店（天猫）\",\"shop_no\":\"024\",\"sub_platform_id\":1,\"telno\":\"010-57238965\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":25,\"shop_name\":\"Yiigoo（国贸店）\",\"shop_no\":\"025\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"460200\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"460000\",\"shop_id\":26,\"shop_name\":\"Yiigoo（三亚店）\",\"shop_no\":\"026\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"110000\",\"shop_id\":28,\"shop_name\":\"Yiigoo（威海三敬）\",\"shop_no\":\"028\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":29,\"shop_name\":\"Yiigoo官方旗舰店（有货线下）\",\"shop_no\":\"029\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":32,\"shop_name\":\"Yiigoo官方旗舰店（一条）\",\"shop_no\":\"032\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":33,\"shop_name\":\"Yiigoo官方旗舰店（拜托了妈妈）\",\"shop_no\":\"033\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":34,\"shop_name\":\"Yiigoo官方旗舰店（隅田川&樱之丸）\",\"shop_no\":\"034\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":35,\"shop_name\":\"Yiigoo官方旗舰店（年糕妈妈）\",\"shop_no\":\"035\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":37,\"shop_name\":\"Yiigoo官方旗舰店（棒棒糖）\",\"shop_no\":\"055\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"16091755\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":17,\"province\":\"0\",\"shop_id\":39,\"shop_name\":\"Yiigoo官方旗舰店（有赞）\",\"shop_no\":\"065\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":40,\"shop_name\":\"Yiigoo官方旗舰店（诚之优品）\",\"shop_no\":\"066\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":41,\"shop_name\":\"Yiigoo官方旗舰店（望京新世界百货）\",\"shop_no\":\"067\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":58,\"province\":\"0\",\"shop_id\":42,\"shop_name\":\"Yiigoo官方旗舰店（云集）\",\"shop_no\":\"068\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"},{\"account_id\":\"\",\"account_nick\":\"\",\"address\":\"\",\"city\":\"0\",\"contact\":\"\",\"district\":\"0\",\"mobile\":\"\",\"platform_id\":127,\"province\":\"0\",\"shop_id\":43,\"shop_name\":\"Yiigoo官方旗舰店（凯叔）\",\"shop_no\":\"069\",\"sub_platform_id\":0,\"telno\":\"\",\"zip\":\"\"}]";
//        List<WdtShop> allShop = JSON.parseArray(json, WdtShop.class);
        return Message.success(allShop);
    }

    private static final String[] EXCEL_HEAD = new String[]{"商品名称", "商品编码", "花色", "数量", "销售金额"};

    @RequestMapping("/exportHotProduct")
    public void exportActivityUser(HotProductSaleQueryReq queryReq, HttpServletResponse response) {
        int count = ygProductService.findHotProductCount(queryReq);
        try {
            ExcelHandler.exportExcelToWebsite(response, count, "商品销售统计", EXCEL_HEAD, new ExcelWriteDataTemplate() {
                @Override
                public List<?> getDataList(Integer start, Integer end) throws ExcelException {
                    queryReq.setStart(start);
                    queryReq.setEnd(end);
                    return ygProductService.findHotProductList(queryReq);
                }

                @Override
                public void writeExcelData(SXSSFRow row, Object o) throws ExcelException {
                    if (o == null) {
                        return;
                    }
                    if (row == null) {
                        System.out.println(1);
                    }
                    YgHotProductModel model = (YgHotProductModel) o;

                    row.createCell(0).setCellValue(model.getProductName());
                    row.createCell(1).setCellValue(model.getProductCode());
                    row.createCell(2).setCellValue(model.getCategoryName());
                    row.createCell(3).setCellValue(model.getSaleNum());
                    row.createCell(4).setCellValue(model.getSalePrice().toString());
                }
            });
        } catch (ExcelException e) {
            e.printStackTrace();
        }

    }

    @RequestMapping("reportOrderUser")
    @ResponseBody
    public Message reportOrderUser(@RequestParam Date startDate, @RequestParam Date endDate, String platformNo,
                                   @RequestParam(defaultValue = "5") int type) {
        endDate = DateUtils.addDays(endDate, 1);
        List<UserCountWrapper.UserCountModel> userCountModels =
                orderCountHandler.userCountRingRatio(startDate, endDate, platformNo, type);
        return Message.success(userCountModels);
    }
}
